/**
 * 项目名称：MSHF
 * 包名称：com.mt.utils
 * 文件名称：FlexUtils.java
 */
package com.mt.utils;

import javax.servlet.http.HttpServletRequest;

import flex.messaging.FlexContext;

/**
 * 类名称：FlexUtils <br>
 * 类描述： <br>
 * 创建人： 马腾 <br>
 * 创建时间：Nov 25, 2012 5:08:07 PM <br>
 * 修改人： 马腾 <br>
 * 修改时间：Nov 25, 2012 5:08:07 PM <br>
 */
public class IPUtils {
	
	public static String getClientIp(){
		return getIpAddr(FlexContext.getHttpRequest());
	}

	private static String getIpAddr(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		if("0:0:0:0:0:0:0:1".equals(ip)){
			ip = "127.0.0.1";
		}
		return ip;
	}
}
